#include <stdio.h>
void show(int arr[], int len,int pro,int next) {
    for (int i = 0; i < len; i++)
    {
        if(i==pro||i==next){
            printf("[%d] ", arr[i]);
        }
        else{
            printf("%d   ", arr[i]);
        }
    }


    printf("\n");
}
void shell_sort(int arr[], int len) {
    int gap, i, j;
    int temp;
    //len=10 len>>1 ---- 1010>>1  ----0101=5  一半的长度
    for (gap = len >> 1; gap > 0; gap >>= 1)
    {
        printf("%d\n",gap);
        for (i = gap; i < len; i++) {
            temp = arr[i];
            for (j = i - gap; j >= 0 && arr[j] > temp; j -= gap){
                arr[j + gap] = arr[j];                
                //show(arr, len,j+gap,j);
            }
            arr[j + gap] = temp;        
            show(arr, len,j+gap,j);
        }
    }
}
int main()
{
    int arr[10]={1,6,7,8,9,2,3,4,5,10};
    show(arr,10,-1,-1);//打印排序前的数组
    shell_sort(arr,10);
    show(arr,10,-1,-1);//打印排序后的数组
    return 0;
}